package com.xinchuang.service.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xinchuang.comment.R;
import com.xinchuang.service.StasticsModService;
import com.xinchuang.utils.CheckUtil;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.text.SimpleDateFormat;

import com.xinchuang.utils.DateUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;

@Service
public class StasticsModServiceImpl implements StasticsModService {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public String getTryOutRecordList(JSONObject jsonObject) {
        //jsonobject解析获取页码
        String pageNum = jsonObject.getString("pageNum");
        //jsonobject解析获取模具工号
        String moldId = jsonObject.getString("moldId");



        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String packingOutList(JSONObject jsonObject) {
        //jsonobject解析获取模具工号
        String moldId = jsonObject.getString("moldId");
        //jsonobject解析获取项目名称
        String projectName = jsonObject.getString("projectName");
        //jsonobject解析获取页码
        String pageNum = jsonObject.getString("pageNum");
        //jsonobject解析获取每页数量
        String pageSize = jsonObject.getString("pageSize");
        if (
                "1".equals(moldId)
                        &&
                        "C673".equals(projectName)
                        &&
                        "10".equals(pageSize)
        ) {
            return "{\"msg\":\"获取成功\",\"code\":200,\"data\":{\"dataList\":[{\"receivedType\":\"材料\",\"returnCount\":\"0\",\"concessionalReceivingCount\":\"0\",\"consumeCount\":\"100\",\"moldWeight\":\"858\",\"receiveDate\":\"2023/1/9\",\"specification\":\"PP\",\"produceMoldCount\":\"40\",\"debugMoldCount\":\"25\",\"qualifiedMoldCount\":\"40\",\"unit\":\"KG\",\"receiveCount\":\"100\",\"excessCount\":\"25\",\"moldId\":\"22239\",\"projectName\":\"C673\"}],\"totalCount\":\"178\"},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String weekYearMonthStastics(JSONObject jsonObject) {
        //jsonobject解析获取查询第几周
        String week = jsonObject.getString("week");
        //jsonobject解析获取查询第几月
        String month = jsonObject.getString("month");
        //jsonobject解析获取查询哪一年
        String year = jsonObject.getString("year");
        if (
                "1".equals(week)
        ) {
            return "{\"msg\":\"获取成功\",\"code\":200,\"data\":{\"dataList\":[{\"numOfOnTimeSets\":\"24\",\"rateOfOnTime\":\"1\",\"numOfSets\":\"9\",\"totalTime\":\"144.5\",\"exceptTime\":\"46.5\",\"companyName\":\"航模\",\"rateOfOnTimeOfT0\":\"1\",\"lossFee\":\"25685\",\"numOfTestSets\":\"24\",\"numOfOnTime\":\"9\",\"totalTryOutFee\":\"79925\"}],\"from\":\"42466\",\"to\":\"43472\"},\"success\":true}";
        }
        if (
                "1".equals(month)
        ) {
            return "{\"msg\":\"获取成功\",\"code\":200,\"data\":{\"dataList\":[{\"numOfOnTimeSets\":\"96\",\"rateOfOnTime\":\"0.94\",\"numOfSets\":\"15\",\"totalTime\":\"643\",\"exceptTime\":\"189.5\",\"companyName\":\"航模\",\"rateOfOnTimeOfT0\":\"1\",\"lossFee\":\"43423\",\"numOfTestSets\":\"102\",\"numOfOnTime\":\"15\",\"totalTryOutFee\":\"346730\"}],\"from\":\"43466\",\"to\":\"43472\"},\"success\":true}";
        }
        if (
                "2023".equals(year)
        ) {
            return "{\"msg\":\"获取成功\",\"code\":200,\"data\":{\"dataList\":[{\"numOfOnTimeSets\":\"208\",\"rateOfOnTime\":\"1\",\"numOfSets\":\"121\",\"totalTime\":\"1298\",\"exceptTime\":\"399\",\"companyName\":\"航模\",\"rateOfOnTimeOfT0\":\"1\",\"lossFee\":\"3432556\",\"numOfTestSets\":\"208\",\"numOfOnTime\":\"121\",\"totalTryOutFee\":\"1233433\"}],\"from\":\"43466\",\"to\":\"43472\"},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String lossStastics() {
        if (1 == 1
        ) {
            return "{\"data\":{\"targetData\":[{\"setupVerification\":\"53535\",\"rectificationAndVerification\":\"116423\",\"month\":\"1\",\"unplannedProofing\":\"21457\",\"planWithoutModificationProofing\":\"2890\",\"materialVerification\":\"1600\",\"T0Verification\":\"44280\",\"textureVerification\":\"45432\"}],\"exceptData\":[{\"breakdownTime\":\"7\",\"month\":\"1\",\"totalTime\":\"643\",\"fixTime\":\"108\",\"waitTime\":\"70\"}],\"detailOfYearData\":[{\"exceptLoss\":\"56434\",\"tryOutTimeInFive\":\"1\",\"month\":\"1\",\"rateOfexceptLoss\":\"28\",\"totalFee\":\"345545\",\"tryOutTime\":\"102\",\"rateOfNormalTimes\":\"0.98%\"}]}}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String packingOutStastics(JSONObject jsonObject) {
        //jsonobject解析获取项目名称
        String projectName = jsonObject.getString("projectName");
        //jsonobject解析获取领用数量
        String receivedCount = jsonObject.getString("receivedCount");
        //jsonobject解析获取合格品数量
        String qualifiedCount = jsonObject.getString("qualifiedCount");
        if (
                "C673后门下本体（左右）".equals(projectName)
        ) {
            return "{\"msg\":\"获取成功\",\"code\":200,\"data\":{\"dataList\":[{\"qualifiedCount\":\"0\",\"typeName\":\"12号箱\",\"receivedCount\":\"0\"},{\"qualifiedCount\":\"0\",\"typeName\":\"10号箱\",\"receivedCount\":\"0\"}]},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String tryOutCountStastics(JSONObject jsonObject) {
        //jsonobject解析获取模具工号
        String moldId = jsonObject.getString("moldId");
        //jsonobject解析获取模具名称
        String moldName = jsonObject.getString("moldName");
        //jsonobject解析获取外观要求
        String appearanceRequire = jsonObject.getString("appearanceRequire");
        //jsonobject解析获取项目经理
        String projectManagerName = jsonObject.getString("projectManagerName");
        //jsonobject解析获取计划T0时间
        String plannedT0Time = jsonObject.getString("plannedT0Time");
        //jsonobject解析获取合计目标试模次数
        String totalTargetTryOutTime = jsonObject.getString("totalTargetTryOutTime");
        //jsonobject解析获取光样前
        String appearanceRequirement = jsonObject.getString("appearanceRequirement");
        //jsonobject解析获取纹理验证
        String textureVerification = jsonObject.getString("textureVerification");
        if (
                "1".equals(moldId)
                        &&
                        "模具名称".equals(moldName)
        ) {
            return "";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String saveTryOutCountStastics(JSONObject jsonObject) {
        //jsonobject解析获取数据列表
        JSONArray dataList = jsonObject.getJSONArray("dataList");
        if (
                "[{\"moldName\":\"模具名称\",\"totalTargetTryOutTime\":\"34\",\"projectManagerName\":\"wangxx\",\"plannedT0Time\":\"2023-08-08\",\"appearanceRequire\":\"外观要求\",\"remark\":\"备注\",\"moldId\":\"GH-Mold-1\",\"appearanceRequirement\":\"23\",\"textureVerification\":\"11\"}]".equals(JSON.toJSONString(dataList))
        ){
            return "{\"msg\":\"保存成功\",\"code\":200,\"data\":{},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String saveTryOutRecordList(JSONObject jsonObject) {
        //jsonobject解析获取统计数据数组对象
        JSONArray dataList = jsonObject.getJSONArray("dataList");
        if (
                "[{\"tongManName\":\"钳工\",\"weekOfYear\":\"第23周\",\"unitPriceOfTime\":\"300\",\"tryOutDeviceModel\":\"型号1\",\"materialVerification\":\"1\",\"moldReachedTime\":\"2022-06-05 11:00:00\",\"targetCount\":\"3\",\"practicalTryOutDate\":\"2022-06-05\",\"realCountOfYear\":\"3\",\"setupDeliveryTime\":\"2022-06-05 11:00:09\",\"unloadTime\":\"0.5\",\"plannedTime\":\"2022-06-05\",\"moldId\":\"1\",\"tryOutPlace\":\"试模地点1\",\"textureVerification\":\"1\",\"isCompletedOnTime\":\"是\",\"reasonName\":\"2\",\"unitPrice\":\"200\",\"loadMoldTime\":\"0.5\",\"rectificationAndVerification\":\"1\",\"unplannedProofing\":\"0\",\"beyondExpectationCount\":\"0\",\"debugTime\":\"1\",\"setupVerification\":\"1\",\"breakdownTime\":\"1\",\"month\":\"5\",\"demoPoduceTime\":\"3\",\"commissioningEngineer\":\"tiaoxx\",\"projectName\":\"wangxx\",\"waitTime\":\"0.5\"}]".equals(JSON.toJSONString(dataList))
        ){
            return "{\"msg\":\"保存成功\",\"code\":200,\"data\":{},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

}
